GBML manual / Motion

move_slide

Moves by (dx, dy) against the current room’s own collision, sliding along whatever it hits (the corner-nudge slide top-down movement wants) instead of stopping dead.

Syntax

move_slide(dx, dy)

Arguments

NameType
dxreal
dyreal

Returns

Nothing.

Description

Moves by (dx, dy) against the CURRENT room's own collision, sliding along whatever it hits - the corner-nudge behavior that makes top-down movement against walls feel right, rather than stopping dead the instant either axis touches something. Reads the room automatically; a Step event calls this directly instead of relying on the engine's own per-frame motion phase, which still runs afterward but does nothing as long as this instance leaves hsp/vsp at 0.

How fast it moves

dx and dy are in pixels, and each call moves the instance once. Called from a Step event, which runs once a frame, the numbers you pass are the speed in pixels per frame. The game runs at 60 frames a second, so move_slide(2, 0) moves 2 pixels right each frame, which is 120 pixels a second.

To move at a speed along an angle, pass dir_x(direction, speed) and dir_y(direction, speed): move_slide(dir_x(bdir, 2.2), dir_y(bdir, 2.2)) moves 2.2 pixels a frame toward bdir, whichever way that points. The speed is the number you pass; move_slide has no speed of its own. If the game runs at 30 frames a second (game speed), each call still moves the same pixels, so the same numbers give half the speed per second.

Slopes

On a room with slopes, move_slide (and move_slide_solid) walks along them. A sideways move into a ramp climbs it: the instance is lifted by the pixel the ground rises, up to 8 pixels in one call. A sideways move off the end of a ramp, from the ground, stays on the ground, again up to 8 pixels. A move into a diagonal wall slides along the wall, and a move up into a sloped ceiling slides along that. A move down onto a slope never slides sideways, so an instance standing on a ramp stays where it is. A wall of full squares is never climbed.

Example

move_slide(btn_dx() * 2, btn_dy() * 2);

Moves the walker by up to 2 pixels on each axis from the d-pad every step, sliding along a wall instead of catching on its corner - the movement most top-down player characters actually want.

On the GBA

Reads the CURRENT room’s collision automatically - a Step event calls this directly instead of relying on the automatic per-frame motion phase, which still runs afterward and is a no-op as long as this instance leaves hsp/vsp at 0.

See also: move_bouncemove_topos_freemove_slide_solidSlopes